home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / s3bas11.zip / WORD.BAS < prev   
BASIC Source File  |  1993-05-14  |  3KB  |  79 lines

  1. 'S3 Collection of functions and subroutines to ease
  2. 'in the checking of PC memory.
  3. '
  4. 'By:  George Spafford Copyright 1993
  5. '
  6. 'No additional libraries required
  7. '
  8. 'v1.0  05/01/93
  9. '
  10. '**************************************************
  11.  
  12. 'If you use these routines, please have the courtesy
  13. 'of registering the tutorial.
  14.  
  15. 'Make sure that you have all of your variables typed
  16. 'correctly before you use one of the following
  17. 'routines.  Use integers where integers are identified (%).
  18. 'Use long integers where long integers are identified (&).
  19.  
  20. 'Int2Long& is a function that accepts a signed
  21. 'integer and returns an unsigned long integer. Since
  22. 'BASIC uses the high bit to toggle the sign of an
  23. 'integer, you must convert it to a long integer before
  24. 'you perform any bit operations on it.
  25.  
  26. DECLARE FUNCTION Int2Long& (IntNumber%)
  27.  
  28. 'BASIC does NOT have a built in facility to PEEK
  29. 'words!  Tell the PeekWord% function where to look,
  30. 'and it will read in a word at that segment and offset.
  31.  
  32. DECLARE FUNCTION PeekWord% (Segment%, Offset%)
  33.  
  34. 'As with Peeks, BASIC does not support a POKE function
  35. 'for words.  This next subroutine adds that capability.
  36. 'Tell the subroutine the segment, offset and word that
  37. 'you wish it to POKE in and it will do so.
  38.  
  39. DECLARE SUB PokeWord (Segment%, Offset%, Word%)
  40.  
  41. 'As you code more and more programs, try to make your code
  42. 'as modular as possible.  By creating objects (OOP systems),
  43. 'you can significantly increase your code reusability.
  44. 'Try to only create the wheel once!  Some of the demos would
  45. 'benefit greatly by judicial use of subroutines.  In order to
  46. 'have top-down readability, I did not modularize the code.
  47. 'Just a FYI   -- George
  48.  
  49. FUNCTION Int2Long& (IntNumber%)
  50.     'If the integer is negative, we need to add 65536
  51.     'to the number (which is 2 * integer limit) to get
  52.     'our new long integer.
  53.  
  54.     IF IntNumber% < 0 THEN
  55.        Int2Long& = 65536 + IntNumber%
  56.     ELSE
  57.        Int2Long& = IntNumber%
  58.     END IF
  59. END FUNCTION
  60.  
  61. FUNCTION PeekWord% (Segment%, Offset%)
  62.     DEF SEG = Segment%              'set segment
  63.     High = PEEK(Offset% + 1)        'High byte is at offset + 1
  64.     Low = PEEK(Offset%)             'Low byte is at offset   
  65.     PeekWord% = (High * 256) + Low  'Compute the word value
  66.     DEF SEG                         'return to default segment
  67. END FUNCTION
  68.  
  69. SUB PokeWord (Segment%, Offset%, Word%)
  70.     DEF SEG = Segment%          'Set segment
  71.     High = (Word \ 256)         'perform integer division
  72.                                 'to compute the high byte
  73.     Low = Word - (High * 256)   'compute the low byte
  74.     POKE (Offset% + 1), High    'POKE in the high byte
  75.     POKE Offset%, Low           'POKE in the low byte
  76.     DEF SEG                     'return to the default segment
  77. END SUB
  78.  
  79.